<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\models\News;
use app\models\Page;
// use yii\helpers\Url;

class ArticleController extends Controller
{
	function actionIndex(){
		$model = new News();
		$count = $model -> getNewsListCount();
		/*
			取消YII page 方法
		*/ 
		// $pagination = new Pagination(['totalCount' => $count]);
		// $pagination->defaultPageSize =5;//设置默认页面内容条数

		$perCount = 10;
		if($count > $perCount){
			$html = Page::getPageHtml($count,'article/index',$perCount,2,3);
		}
		$data = $model -> getNewsList($perCount);
		
		return $this -> render('index',['data'=>$data,'pageHtml'=>$html,'count'=>$count]);
	}
	function actionContent($catSlug,$slug){
		$model = new News();
		if($data = $model-> getNewsContent($catSlug,$slug)){
			$data -> read_num +=1;
			$data -> save();
			return $this -> render('content',['data'=>$data->attributes]);
		}else{
			return Yii::$app->response->statusCode = 404;
		}
	}
	// function actionGetNewsComment(){

	// }
	function actionSetNewsComment(){
		/*
			采用第三方评论系统 弃
		*/
		exit;
		if($_POST['nickname'] and $_POST['email'] and $_POST['content']){
			$model = new Comment();
			if($model -> setCommet($_POST)){
				echo "恭喜你，发布成功！";
			}else{
				echo "抱歉，发布失败了，请稍后再试，或者联系管理员！";
			}
		}else{
			echo "您的评论未填写完整";
		}

	}
}